//
//  CarShipConfirmViewController.m
//  EasyToo
//
//  Created by linshengqin on 13-9-2.
//
//

#import "CarShipConfirmViewController.h"
#import "ConfirmDataModel.h"
#import "NetworkAlertView.h"
@interface CarShipConfirmViewController ()

@end

@implementation CarShipConfirmViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
     [self.view setBackgroundColor:BackgroundColor];
    datamodel = [ConfirmDataModel shareData];
    [CarShipTaxManager shareManager].delegate = self;
    subLabeTextlArr = [[NSMutableArray alloc]initWithObjects:
                       [NSString stringWithFormat:@"车牌号:%@",datamodel.CarNumStr],
                       [NSString stringWithFormat:@"购买年份:%@",datamodel.BuyDateStr],
                       [NSString stringWithFormat:@"业务本金:%@",datamodel.BaseCostStr],
                       [NSString stringWithFormat:@"快递费用:%@",@"0元"],
                       [NSString stringWithFormat:@"联系电话:%@",datamodel.phoneNumStr],
                       [NSString stringWithFormat:@"支付方式:%@",@"银联"],
                       [NSString stringWithFormat:@"%@",datamodel.allCostStr], nil] ;
    NSLog(@"datamodel : %@",datamodel) ;
    
    [self initScrollView];
    [self createMainView];
    [self createComfirmButton];
}

-(void)initScrollView
{
    _bgScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, [DeviceUtil getScreenWidth], [DeviceUtil getScreenHeight])];
    [self.view addSubview:_bgScrollView];
    _bgScrollView.contentSize = CGSizeMake(320, 700);
    _bgScrollView.showsVerticalScrollIndicator = YES;
    
}

-(void)createMainView
{
    UIView *mainView = [[UIView alloc]initWithFrame:CGRectMake(10 , 20 , 300, 300) ];
    mainView.clipsToBounds = YES ;
    UIImageView *imageView =[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 300, 340)];
    imageView.image = [UIImage imageNamed: @"list.png" ];
    [self createHeadlabel:imageView];
//    [self createyesImageview:imageView];
    [self createSubLabel :imageView ];
    [self createAcountlabel:imageView];
    [mainView addSubview:imageView];
    [_bgScrollView addSubview:mainView];
}


-(void)createHeadlabel:(UIImageView*)imageView
{
    UILabel *headLabel = [[UILabel alloc]initWithFrame:CGRectMake(120, -15, 100, 50)];
    headLabel.text = @"确认信息" ;
    headLabel.textColor = [UIColor redColor];
    
    [imageView addSubview:headLabel];
    [headLabel release];
}
-(void)createyesImageview :(UIImageView*)imageview
{
    UIImageView *yesview = [[UIImageView alloc]initWithFrame:CGRectMake(80, -15 ,30, 50)];
    yesview.image = [UIImage imageNamed:@"cp_ssqueren1.png"];
    [imageview addSubview:yesview];
}
-(void)createAcountlabel :(UIImageView *)imageview
{
    UILabel *acount = [[UILabel alloc]initWithFrame:CGRectMake(100, 260, 190, 30)];
    acount.text = [NSString stringWithFormat:@"合计:%@元" ,[subLabeTextlArr objectAtIndex:6]] ;
    
    acount.textColor  = [UIColor redColor];
    acount.textAlignment = NSTextAlignmentRight ;
    [imageview addSubview :acount ] ;
}
-(void)createSubLabel :(UIImageView *)imageview
{
    for(int i = 0 ; i < 6  ;i++)
    {
        UILabel *label = [[ UILabel alloc]initWithFrame:CGRectMake(25, 60 + 35*i, 200, 20)];
        label.text = [subLabeTextlArr objectAtIndex:i];
        label.textColor = [UIColor blackColor];
        [imageview addSubview:label];
    }
}

-(void)createComfirmButton
{
    UIButton *btn=[[UIButton alloc]initWithFrame:CGRectMake(10, 360, 300, 50)];
    [btn setBackgroundImage:[UIImage imageNamed:@"button_3.png"] forState:UIControlStateNormal];
    [btn setTitle:@"确认支付" forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(ComfirmPay) forControlEvents:UIControlEventTouchUpInside];
//    btn.layer.cornerRadius =10 ;
    
    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [_bgScrollView addSubview:btn];
    [btn release];
    
}
-(void)ComfirmPay
{
    NSLog(@"comfirm pay");
    NSString* license = [datamodel.CarNumStr copy];
    NSString* amount = [datamodel.allCostStr copy];
    NSString* mobile = [datamodel.phoneNumStr copy];
    [[CarShipTaxManager shareManager]orderCarShipTax:license andDisplacement:@"2" andAmount:amount andMobile:mobile];
    [[NetworkAlertView shareView]showNetView];
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (void)dealloc
{
    [subLabeTextlArr release] ,subLabeTextlArr = nil;
    [super dealloc];
}

- (void)onOrderCarShipTaxFinish:(BOOL)isSuccess Tn:(NSString *)tn
{
    [[NetworkAlertView shareView] delView];
    
    [UPPayPlugin startPay:tn sysProvide:nil spId:nil mode:PAY_MODE_REALEASE viewController:self delegate:self];
}

-(void)UPPayPluginResult:(NSString*)result
{
    NSString *alertString = nil;
    if ([result isEqualToString:@"success"])
    {
        alertString = @"交易成功";
    }
    else if ([result isEqualToString:@"cancel"])
    {
        alertString = @"交易取消";
    }
    else
    {
        alertString = @"交易失败";
    }
    
    UIAlertView *alert = [[UIAlertView alloc]  initWithTitle:@"支付结果" message:alertString  delegate:self cancelButtonTitle:@"确定" otherButtonTitles: nil];
    [alert show];
    
}

@end
